package com.sttk.secreconeclick.bookkeep.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.basic.ProviderMultiAdapter;
import com.sttk.secreconeclick.bookkeep.R;
import com.sttk.secreconeclick.bookkeep.bean.SaveRecordBean;

import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;


public class SaveRecordAdapter extends ProviderMultiAdapter<SaveRecordBean> {

    public SaveRecordAdapter() {
        addItemProvider(new SaveRecordItemProvider());
    }

    private class SaveRecordItemProvider extends BaseItemProvider<SaveRecordBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_save_record;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, SaveRecordBean bean) {
            baseViewHolder.setText(R.id.tvSaveRecordItemDate, TimeUtils.millis2String(bean.getDate(),new SimpleDateFormat("yyyy-MM-dd")));
            if (bean.isSave()) {
                baseViewHolder.setTextColor(R.id.tvSaveRecordItemMoney, Color.parseColor("#00B868"));
                baseViewHolder.setText(R.id.tvSaveRecordItemMoney, "+" + String.format("%.2f", bean.getMoney()));
            } else {
                baseViewHolder.setTextColor(R.id.tvSaveRecordItemMoney, Color.parseColor("#323433"));
                baseViewHolder.setText(R.id.tvSaveRecordItemMoney, "-" + String.format("%.2f", bean.getMoney()));
            }
        }
    }
}
